package dian.qing.li.demo.security.config.listener;

import dian.qing.li.demo.security.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @program: seedland_uc_git
 * @description:
 * @author: EC_liqingdian
 * @create: 2020-04-15 16:07
 **/
@Slf4j
@WebListener("taskListenter")
public class TaskListenter implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // 初始化
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // 销毁
        log.info("关闭线程");
        //关闭线程或线程池
        ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) SpringUtils.getBean("scheduler");
        scheduler.shutdown();
        ThreadPoolTaskExecutor executor = SpringUtils.getBean("executor", ThreadPoolTaskExecutor.class);
        executor.shutdown();
    }
}
